package com.job.ali;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @ClassName: test.Ali3
 * @Description:
 * @Author: 12071
 * @Date: 2022/4/15 21:43
 *
 * 4
 * 1 1 3 2
 * 1 2
 * 1 3
 * 3 4
 */
public class Ali3 {
    static int[] vals;
    static int[] weights;
    static ArrayList<ArrayList<Integer>> map;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        vals = new int[n+1];
        for (int i = 1; i <= n; i++) {
            vals[i] = sc.nextInt();
        }
        sc.nextLine();
        map = new ArrayList<>();
        for (int i = 0; i <= n; i++) {
            map.add(new ArrayList<Integer>());
        }
        for (int i = 0; i < n-1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            map.get(a).add(b);
            sc.nextLine();
        }
        weights = new int[n+1];
        for (int i = 1; i <= n; i++) {
            weights[i] = dfs(i);
        }
        System.out.println(Arrays.toString(weights));





    }

    public static int dfs(int node){
        ArrayList<Integer> list = map.get(node);
        int sum =vals[node];
        for (int item : list) {
            sum+=dfs(item);
        }
        return sum;
    }
}
